
package logic.forms;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import logic.beans.State;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class StateForm extends ElementForm<State> {
	private static final long serialVersionUID = 1L;
	
	@Override
	public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		if (getElement().getName() == null || getElement().getName().isEmpty()) {
			errors.add("name",new ActionMessage("state.register.error.name.empty"));
		}
		
		return errors;
	}
	
	@Override
	public List<String> getEmptyPropertyNames() {
		List<String> result = new ArrayList<String>();
		
		if (isFieldEmpty(getElement().getName()))
			result.add("name");
		if (isFieldEmpty(getElement().getDescription()))
			result.add("description");
		
		return result;
	}
}
